package jwxx.server;
import java.sql.ResultSet;
import java.sql.SQLException;
import jwxx.server.DbOperator;
import jwxx.server.SSkillEffect;
public class SSkillEffectSql {
	private int n;
	private ResultSet rs;
	
	public int insert(SSkillEffect cb)throws SQLException{
		String sql = "insert into skill_effect_table (skill_id,metal,wood,water,fire,earth,hit_plus,dam_plus,hp_plus,probability,skills_attribute)values(?,?,?,?,?,?,?,?,?,?,?)";
		Object [] obj = new Object []{cb.getSkillId(),cb.getMetal(),cb.getWood(),cb.getWater(),cb.getFire(),cb.getEarth(),cb.getHitPlus(),cb.getDamPlus(),cb.getHpPlus(),cb.getProbability(),cb.getSkillAttribute()};
				
		DbOperator db = new DbOperator();
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;
		}

	public int delete(int skill_id)throws SQLException{
		String sql = "delete from skill_effect_table where skill_id=?";
		Object [] obj = new Object []{new Integer(skill_id)};
		DbOperator db = new DbOperator();		
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}
		db.close();	
		return n;
	}		

	public int update(SSkillEffect cb)throws SQLException{
		String sql = "update skill_effect_table set metal=?,wood=?,water=?,fire=?,earth=?,hit_plus=?,dam_plus=?,hp_plus=?,probability=?,skills_attribute=? where skill_id=?";
		Object [] obj = new Object []{cb.getMetal(),cb.getWood(),cb.getWater(),cb.getFire(),cb.getEarth(),cb.getHitPlus(),cb.getDamPlus(),cb.getHpPlus(),cb.getProbability(),cb.getSkillAttribute(),new Integer(cb.getSkillId())};
		DbOperator db = new DbOperator();	
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;		
	}	
	
	public ResultSet selectAllClass()throws SQLException{
		String sql="select * from skill_effect_table";
		DbOperator db = new DbOperator();
		try{
			rs=db.executeQuery(sql, new Object[]{});
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return rs;
	}
	
	public SSkillEffect selectById(int skillid)throws SQLException{		
		String sql2 = "select * from skill_effect_table where skill_id=?";
		DbOperator db = new DbOperator();
		SSkillEffect cb = new SSkillEffect();
		try{
			rs = db.executeQuery(sql2, new Object[]{new Integer(skillid)});
			while(rs.next()){
				cb.setSkillId(rs.getInt("skill_id"));
				cb.setMetal(rs.getInt("metal"));
				cb.setWood(rs.getInt("wood"));
				cb.setWater(rs.getInt("water"));		
				cb.setFire(rs.getInt("fire"));
				cb.setEarth(rs.getInt("earth"));
				cb.setHitPlus(rs.getInt("hit_plus"));
				cb.setDamPlus(rs.getInt("dam_plus"));		
				cb.setHpPlus(rs.getInt("hp_plus"));
				cb.setProbability(rs.getInt("probability"));
				cb.setSkillAttribute(rs.getInt("skills_attribute"));		
			}
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return cb;
	
		}

}
